package com.text.day2_4.teampk;


import java.util.Random;

public class PkGroup {
    public static int pk(People hero1,People hero2) {
        int a = 1;
        while (true) {
            System.out.println();
            System.out.println(hero1.getName() + "hp:" + hero1.getHp() + "---- VS ----" + hero2.getName() + "hp:" + hero2.getHp());
            System.out.println("=========第" + a + "回合，ready fight=========");
            if (a % 2 == 1) {
                hero1.fight(hero2);
                if (!hero2.isAlive()) return 2;
                hero2.fight(hero1);
                if (!hero1.isAlive()) return 1;
            } else {
                hero2.fight(hero1);
                if (!hero1.isAlive()) return 1;
                hero1.fight(hero2);
                if (!hero2.isAlive()) return 2;
            }
            a++;
        }
    }
    public static void teamPk(Fightable[] team1,Fightable[] team2) {
        int a = 0;
        int b = 0;
        while (true) {
            if (a != team1.length && b!=team2.length) {
                if (pk((People) team1[a],(People) team2[b]) == 1) {
                    a++;
                } else
                    b++;
            } else
                break;
        }
        if (a == team1.length) {
            System.out.println("二队胜利");
        } else
            System.out.println("一队胜利");
    }
    public static void main(String[] args) {
        Random random = new Random();
        People hero1 = new People("一号", 100, random.nextInt(20) + 20);
        People hero2 = new People("二号", 100, random.nextInt(20) + 20);
        People hero3 = new People("三号", 100, random.nextInt(20) + 20);
        People hero4 = new People("四号", 100, random.nextInt(20) + 20);
        People hero5 = new People("五号", 100, random.nextInt(20) + 20);
        People hero6 = new People("六号", 100, random.nextInt(20) + 20);
        People[] people1 = {hero1, hero2, hero3};
        People[] people2 = {hero4, hero5, hero6};
        System.out.println("========成员信息=========");
        System.out.println("一队：");
        for (People people : people1) {
            System.out.println(people);
        }
        System.out.println("二队：");
        for (People people : people2) {
            System.out.println(people);
        }
        System.out.println();
        System.out.println("============开始组队pk==========");
        System.out.println();
        teamPk(people1,people2);
    }
}
